package financial.sharing.center.receivable.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.receivable.model.entity.ReceivableBill;
import financial.sharing.center.receivable.service.ReceivableBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @ClassName ReceivableBillController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/17
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/receivable/receivable/bill/")
public class ReceivableBillController {

    @Autowired
    private ReceivableBillService receivableBillServiceImpl;

    @PostMapping(value = "get/all/receivable/bill")
    public R getAllReceivableBill(Integer contractId,
                                  Integer accruedId,
                                  Integer billId,
                                  Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<ReceivableBill> result = this.receivableBillServiceImpl.getAllReceivableBill(contractId,accruedId,billId);
        return R.ok(result);
    }

    @PostMapping(value = "create/one/receivable/bill")
    public R createOneReceivableBill(BigDecimal billAmount,
                                     String payableCompanyName,
                                     String receivableCompanyName){
        Integer result = this.receivableBillServiceImpl.createOneReceivableBill(billAmount,payableCompanyName,receivableCompanyName);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/receivable/bill")
    public R compileOneReceivableBill(@RequestBody ReceivableBill receivableBill){
        Integer result = this.receivableBillServiceImpl.compileOneReceivableBill(receivableBill);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/receivable/bill")
    public R deleteOneReceivableBill(Integer id){
        Integer result = this.receivableBillServiceImpl.deleteOneReceivableBill(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/map/receivable/bill")
    public Map<Integer,BigDecimal> getMapReceivableBill(){
        return this.receivableBillServiceImpl.getMapReceivableBill();
    }

}
